<template>


    <SearchTablePage :search-config="baseTableSearchModel" :table-config="baseTableModel" />

</template>

<script lang="ts" setup>
defineOptions({
    name: 'StoreInfoOutBatchDetailPageData',   //全局别名
    title: '表格页',   //标题
});
// 接口
import StoreInfoOutBatchDetailApi from '/@/api//StoreInfoOutBatchDetailApi.ts';

import StoreInfoApi from '~/src/api/webPath/StoreInfoApi';

import FORM_FIELD_TYPE from '/@/constants/FormFieldType';
import VDialog from '/@/utils/dialogUtil.ts'
import { useTemplateName } from '~/src/utils/useTemplateName';

const router = useRouter();
const baseTable = ref(null as any);
const baseTableSearch = ref(null as any);
const editRef = ref<any>(null);
const exportXlsName = useTemplateName("template_type_8")
const storeType = ref()
const storeList = ref()
onMounted(async () => {
    // TODO 更换为全量获取仓库列表
    const data = (await StoreInfoApi.getPageData({})).data
    console.log("data:", data)
    storeList.value = data.records.map(item => ({ label: item.storeName, value: item.storeName }))
    console.log("supplierTypeList", storeList.value)
    // data.map(x=>{label:data})
})

// 表格搜索初始化searchModel
const baseTableSearchModel = ref({
    columnCount: 4,
    expandLimit: 6,
    autoFit: true,
    columnWidth: '320px',
    labelPosition: 'right',
    labelWidth: '100px',
    items: [ //搜索项初始化

        // {
        //             label: "主键",
        //             field: "id",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //    },
        {
            label: "仓库类型",
            field: "storeType",
            clearable: true,
            type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
            options: storeList,
            placeholder: "请输入",
        },
        // {
        //     label: "库存记录ID",
        //     field: "detailId",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.INPUT,

        //     placeholder: "请输入",

        // },

        // {
        //     label: "库存记录ID",
        //     field: "storeInfoDetailId",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.INPUT,

        //     placeholder: "请输入",

        // },

        // {
        //     label: "出库记录ID",
        //     field: "outRecordId",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.INPUT,

        //     placeholder: "请输入",

        // },

        // {
        //     label: "入库记录ID",
        //     field: "inRecordId",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.INPUT,

        //     placeholder: "请输入",

        // },

        // {
        //             label: "物料ID",
        //             field: "materialId",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        {
            label: "物料编码",
            field: "materialCode",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        {
            label: "物料名称",
            field: "materialName",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        {
            label: "规格",
            field: "materialSpc",
            clearable: true,
            type: FORM_FIELD_TYPE.INPUT,

            placeholder: "请输入",

        },

        // {
        //     label: "出库数量",
        //     field: "outNum",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.INPUT,

        //     placeholder: "请输入",

        // },
        // {
        //     label: "领用日期",
        //     field: "outDate",
        //     clearable: true,
        //     type: FORM_FIELD_TYPE.DATE,
        //     placeholder: "请输入",
        // },

        // {
        //             label: "所属公司ID",
        //             field: "companyId",
        //             clearable: true,
        //             type: FORM_FIELD_TYPE.INPUT,

        //            placeholder:"请输入",

        //         },

        //  

    ],

    buttons: [    //功能区域
        // {
        //     name: "导出",
        //     buttonClass: 'primary',
        //     width: 100,
        //     click: ({ row, handlers }) => {   //暴露的方法钩子
        //         StoreInfoOutBatchDetailApi.pageDataXls(handlers.getRequestParams(), handlers.getXlsTitle())
        //     }
        // },

        {
            name: "导出",
            buttonClass: 'primary',
            width: 100,
            click: ({ row, handlers }) => {        // 点击回调事件方法钩子，  点击触发

                VDialog.open({
                    title: '导出',

                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/storeInfoInspectionRecords/daochu',
                        query: {},

                    },

                    callBack: (data: any) => {
                        storeType.value = data.supplierType;
                        StoreInfoOutBatchDetailApi.pageDataXls(handlers.getRequestParams(), handlers.getXlsTitle(), exportXlsName.value, storeType.value)
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });

            },
        },
        // {
        //     name: "新增",
        //     buttonClass: 'primary',
        //     width: 100,
        //     click: ({ row, handlers }) => {        // 点击回调事件方法钩子，  点击触发

        //         VDialog.open({
        //             title: '新增',

        //             content: { //内容初始形式
        //                 type: 'component', //text:"",预留文本
        //                 name: '/storeInfoOutBatchDetail/edit',
        //                 query: {},

        //             },

        //             callBack: (data: any) => {
        //                 handlers.refresh()
        //             },
        //             onClose: () => {
        //                 console.log("对话框已关闭");
        //             },
        //         });

        //     },
        // },
        // {
        //     name: "批量删除",
        //     buttonClass: 'danger',
        //     width: 100,
        //     isShow: (row: any) => {
        //         return false;
        //     },
        //     click: () => {   //暴露的方法钩子
        //         console.log(baseTable.value.getSelection());
        //     },
        // },
    ]
})
// 表格初始化Model
const baseTableModel = ref({
    border: true,
    pagination: true,
    inline: true,
    selectable: true,
    isFullscreen: false,
    minWidth: '200px',
    data: {    //table  初始化
        current: 1,
        size: 10,
        total: 100,
        data: []
    },
    requestData: { api: StoreInfoOutBatchDetailApi.getPageData, query: {} },   //数据源 参数有效性： 'steady|transient'
    columns: [
        //    {
        //     label: "主键",
        //     field: "id",
        //     width:100,
        //       },
        //    {
        //     label: "库存记录ID",
        //     field: "detailId",
        //     width:150,
        //       },
        // {
        //     label: "库存记录ID",
        //     field: "storeInfoDetailId",
        //     width: 150,
        //     noExported: true,
        // },
        // {
        //     label: "出库记录ID",
        //     field: "outRecordId",
        //     width: 150,
        //     noExported: true,
        // },
        // {
        //     label: "入库记录ID",
        //     field: "inRecordId",
        //     width: 150,
        //     noExported: true,
        // },
        {
            label: "仓库类型",
            field: "storeType",
            width: 180,
        },
        {
            label: "领用日期",
            field: "outDate",
            width: 200,
            // noExported: true,
            fieldFormat: "date"
        },
        {
            label: "物料编码",
            field: "materialCode",
            width: 180,
        },
        {
            label: "物料名称",
            field: "materialName",
            width: 190,
        },
        {
            label: "规格",
            field: "materialSpc",
            width: 180,
        },
        {
            label: "出库数量",
            field: "outNum",
            width: 120,
        },
        {
            label: "当前库存",
            field: "inventoryNum",
            width: 120,
        },
        //    {
        //     label: "所属公司ID",
        //     field: "companyId",
        //     width:150,
        //       },
        {
            label: "创建时间",
            field: "create_time",
            width: 220,
        },
        {
            label: "更新时间",
            field: "update_time",
            width: 220,

        },
    ],


    actions: [
        {
            name: "详情",

            buttonClass: 'primary',
            buttonType: 'text',
            click: ({ row, index, handlers }) => {

                //router.push({name: 'CompanyInfoDetail',})
                VDialog.open({
                    title: '详情',
                    content: { //内容初始形式
                        type: 'component', //text:"",预留文本
                        name: '/storeInfoOutBatchDetail/detail',
                        query: { storeInfoOutBatchDetailId: row.id },
                    },
                    callBack: (data: any) => {
                        handlers.refresh()
                    },
                    onClose: () => {
                        console.log("对话框已关闭");
                    },
                });
            },
            isShow: (row: object) => {
                return true;
            },
            fixed: 'right'
        },
        // {
        //     name: "编辑",
        //     buttonClass: 'primary',   //按钮颜色控制
        //     buttonType: 'text',      // 按钮风格   text  link  button
        //     isShow: (row: object) => {  //根据业务做动态隐藏张氏
        //         return true
        //     },
        //     click: ({ row, index, handlers }) => {        // 点击回调事件方法钩子，  点击触发

        //         VDialog.open({
        //             title: '编辑',
        //             content: { //内容初始形式
        //                 type: 'component', //text:"",预留文本
        //                 name: '/storeInfoOutBatchDetail/edit',
        //                 query: { storeInfoOutBatchDetailId: row.id },

        //             },

        //             callBack: (data: any) => {
        //                 handlers.refresh()
        //             },
        //             onClose: () => {
        //                 console.log("对话框已关闭");
        //             },
        //         });

        //     },
        //     fixed: 'right'
        // },

        {
            name: "删除",
            buttonClass: 'danger',
            buttonType: 'text',
            fixed: 'right',
            click: ({ row, index, handlers }) => {
                $baseConfirm('您确定要删除当前项吗', null, async () => {
                    const { message } = await StoreInfoOutBatchDetailApi.del({ storeInfoOutBatchDetailIds: row.id })
                    $baseMessage(message, 'success', 'vab-hey-message-success');
                    handlers.refresh()

                })

            }
        },

    ]

})



onActivated(() => {
})



</script>
